﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace week_add
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if ((text_a.Text == "") || (text_b.Text == "") || (text_c.Text == ""))
            {
                MessageBox.Show(this, "不能为空", "msg", MessageBoxButtons.OK, MessageBoxIcon.Information);//产生出错提示消息盒
                return;
            }
            try
            {
            int a = Convert.ToInt32(text_a.Text);
            int b = Convert.ToInt32(text_b.Text);
            int c = Convert.ToInt32(text_c.Text);
           

                if (c == a + b)
                {
                    lbl_Msg.Text = "你答对了，真帅！";
                }
                else
                {
                    lbl_Msg.Text = "你答错了，要加油呀！";
                    text_c.Focus();//让txt_c控件获得输入焦点
                }
            }  
            catch (Exception e1)
            {
                MessageBox.Show(this, e1.Message, "msg", MessageBoxButtons.OK, MessageBoxIcon.Warning);//产生错误提示消息盒
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int a, b;
            Random r = new Random();
            a = r.Next(1, 10);
            b = r.Next(1, 10);

            text_a.Text = a.ToString();
            text_b.Text = b.ToString();

            text_c.Text = "";
            text_c.Focus();
        }
    }
}
